<?php 
	
namespace app\tranfer\controller;
use think\Db; // 引用DB类
use think\Request;
use think\Session;

class Tranfer
{

    // http://127.0.0.1:85/index.php?s=/tdled/test
    /*
    {
        "GDH": "AK1970254",
        "LSM": "002"
    }
	*/
    public function index(){
    	
    }
    
	
	//待转账信息表单
	public function tranferList($id){
		//获取每页显示的条数
			$limit = Request::instance()->param('limit');
			//获取当前页数
			$page = Request::instance()->param('page');
			//计算出从哪条开始查询
			$tol = ($page-1)*$limit+1;
			//查询出当前页数显示的数据
			$list = Db::table("tranfer")
				 -> where("user_name",$id)
				 -> where("tranfer_id",">=","$tol")
				 -> limit("$limit")
				 -> order("tranfer_time asc")
				 -> select();
				 
			$list1 = Db::table("tranfer")
				 -> where("user_name",$id)
				 -> select();
			$count = count($list1);
			/*$list = Db::table('think_article')
					-> alias('a')
					-> join('think_category c','a.caId=c.category_id')
					-> where("a.article_id",">=","$tol")
					-> where('a.user_id',$user_id)
					-> order('a.article_id asc')
					-> limit("$limit")
					-> select();*/
			return json(["code"=>"0","msg"=>"","count"=>$count,"data"=>$list]);
	}
	
	public function success_Tranfer($tranfer_id){
		//转账状态=》tranfer_status 0:未转账 1 转账成 2转账失败
		$msg	= "";
		$code	= 1;
		$arr	="";
		foreach($tranfer_id as $tranfer_id){
			$update	= Db::table('tranfer')
			   	   -> where('tranfer_id', $tranfer_id)
			   	   -> update(
			   	   		[
			   	   			"tranfer_status"	=> 1
			   	   		]);
			if($update){
				$msg	= "操作成功";
				$code	= 1;
			}else{
				$arr=$arr.$tranfer_id.' ';
				//dump($arr);
				$msg	= "ID为[".$arr."]的订单操作失败，请重试";
				$code	= 0;
			}
		}
		return json(["code"=>$code,"msg"=>$msg]);
	}
	
	
	
	
}
